<?php
/*
*	验证码程序/打包下载程序 @zairwolf
*/

require_once 'include/init.php';

require_once ROOT.'include/image.func.php';
include _config('info');

//@set_time_limit(0);

//可替换变量的js 2009-5-22
if($action=='js'){
	define('FreeSuffix', '.js');
	$type=_get('type');
	if($type='main'){
		$tpl = new T('../../include/js/main');
		$tpl->assign(array(
			'minlength'	=>30,
		));
		$tpl->output();
		exit();
	}
}


if($action=='gethashimg') {//生成验证码
	ob_end_clean();
	_secode_generate();
}

if($action=='getavatar'){
	$id=_get('id');
	$file='data/avatar/default.gif';
	if($id){
		if(file_exists("data/avatar/$id.gif")){
			$file="data/avatar/$id.gif";
		}elseif(file_exists("data/avatar/$id.jpg")){
			$file="data/avatar/$id.jpg";
		}
	}
	ob_end_clean();
	if(substr($file,'-3')=='gif'){
		header('Content-type: image/gif');
	}else{
		header('Content-type: image/jpeg');
	}
	echo file_get_contents($file);
	exit;


}

//zip打包下载
if($action=='zipdownload'){
	include _config('read');

	if(!$_SYSTEM['READ']['download_package']) b('打包下载功能尚未开启，请联系管理员');
	if(!$_G['user_id'] && !$_SYSTEM['READ']['download_package_guest']) b('请先登录');

	$sitename   = $_SYSTEM['SYSTEM']['SITE_NAME'];
	$siteurl    = $_SYSTEM['SYSTEM']['SITE_ADDR'];
	$filecomm   = convert("这里放置简介内容\n\n发表时间:  ".rdate(TIMESTAMP, 'Y-m-d H:i')."\n\n制作方:  $sitename\n\n网址: $siteurl\n\n    欢迎访问本站", 'utf-8', 'gbk');

	require_once ROOT.'include/zip.cls.php';
	$zipname = ROOT."data/zip/test.zip";//临时zip
	if(!is_file($zipname) || TIMESTAMP - filemtime($zipname) > 86400) {//对临时zip是否过期的检查
		$zip        = new zip($zipname);
		$zipfilearr = rlistfile(ROOT."html/test");//放置要打包的目录
		$gbktitle   = convert('zip中文件夹名称', 'utf-8', 'gbk');
		foreach($zipfilearr as $val) {
			$val = convert($val, 'utf-8', 'gbk');
			$zip->addFile(ROOT."html/test/$val", "$gbktitle/$val");
		}
		$zip->save($filecomm);
		unset($zip);
	}

	ob_end_clean();

	header('Content-Encoding: none');
	header('Content-Type: application/zip');
	header('Content-Length: '.filesize(ROOT.'data/zip/test.zip'));
	header('Content-Disposition: attachment; filename=test.zip');

	readfile(ROOT.'data/zip/test.zip');
	exit;
}

//图片输出出错信息 2009-5-12
function bb($path){
	header('Content-type: image/jpeg');
	echo file_get_contents(ROOT."images/$path.jpg");
	exit();
}